<%--
  Created by IntelliJ IDEA.
  User: DongZhengWei
  Date: 2018/11/5
  Time: 9:41
  新增部门
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
	String _id=request.getParameter("_");
%>

<form id="form_department_input" class="form-horizontal">
	<input type="hidden" name="keyId" id="keyId" value="${department.id}"/>

	<c:if test="${parentDept!=null}">
		<div class="form-group">
			<label class="col-md-2 control-label">上级部门</label>
			<div class="col-md-8">
				<input disabled type="text" class="form-control" id="parentName" name="parentName" value="${parentDept.name}" placeholder="上级部门" />
				<input type="hidden" id="parentId" name="parentId" value="${parentDept.id}" />
			</div>
		</div>
	</c:if>

	<div class="form-group">
		<label class="col-md-2 control-label">部门名称</label>
		<div class="col-md-8">
			<input type="text" class="form-control" id="name" name="name" value="${department.name}" placeholder="请输入部门名称" />
		</div>
	</div>

	<div class="form-group">
		<label class="col-md-2 control-label">部门描述</label>
		<div class="col-md-8">
			<input type="text" name="description" id="description" value="${department.description}" class="form-control" placeholder="请输入部门描述">
		</div>
	</div>

</form>

<script>

    $(function(){
        fn_department_input_validate();
    });

    //表单验证
	function fn_department_input_validate(){
        __init_bootstrapValidator("form_department_input", {
            name : {
                validators : {
                    notEmpty : {
                        message : "请输入部门名称"
					}
				}
			}
		});
	}

	//保存
	function fn_department_input_save(callback){
	    if(__is_validate("form_department_input")){
            __confirm_dialog(null, "确定保存吗？", function(){
                __form_save("form_department_input", "<%=path%>/main/department/save", function(data){
                    callback(data.state === 1 ? data.data : null);
				})
			});
		}
	}

</script>